

describe('App.OwnAccountTransfer', function() {
    var transfer;
    beforeEach(function(){
        transfer = App.OwnAccountTransfer.create({
        });
    });

    describe('validation', function() {
        it('amount less than .01', function() {
            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('0.0');
            } catch(e) {
            }
            expect(BreezeException.create).toHaveBeenCalledWith({errorMessage: App.i18n.getTranslations().get('error.minimumAmountOwnAccountError')});
        });
        it('valid amount', function() {
            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('10.0');
            } catch(e) {
            }
            expect(BreezeException.create).not.toHaveBeenCalled();
        });
    });
    describe('validation for cash advance', function() {

        beforeEach(function(){
            transfer.fromAccount = App.CardAccount.create();
        });

        it('amount less than 1 for cash advance', function() {

            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('0.1');
            } catch(e) {
            }
            expect(BreezeException.create).toHaveBeenCalledWith({errorMessage: App.i18n.getTranslations().get('error.minimumAmountCashAdvanceError')});
        });
        it('valid amount for cash advance', function() {
            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('10.0');
            } catch(e) {
            }
            expect(BreezeException.create).not.toHaveBeenCalled();
        });
    });
});

describe('App.ThirdPartyTransfer', function() {
    var transfer;
    beforeEach(function(){
        transfer = App.ThirdPartyTransfer.create({
        });
    });
    describe('validation', function() {
        it('amount less than 100', function() {
            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('1.0');
            } catch(e) {
            }
            expect(BreezeException.create).toHaveBeenCalledWith({errorMessage: App.i18n.getTranslations().get('error.minimumAmountError')});
        });
    });
    it('valid amount', function() {
        spyOn(BreezeException, 'create');
        try {
            transfer.validateAmount('101.0');
        } catch(e) {
        }
        expect(BreezeException.create).not.toHaveBeenCalled();
    });

    describe('validation for cash advance', function() {

        beforeEach(function(){
            transfer.fromAccount = App.CardAccount.create();
        });

        it('amount less than 1 for cash advance', function() {

            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('0.1');
            } catch(e) {
            }
            expect(BreezeException.create).toHaveBeenCalledWith({errorMessage: App.i18n.getTranslations().get('error.minimumAmountCashAdvanceError')});
        });
        it('valid amount for cash advance', function() {
            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('10.0');
            } catch(e) {
            }
            expect(BreezeException.create).not.toHaveBeenCalled();
        });
    });

    describe('validation for decimal values for IBFT and VMT', function() {

        it('IBFT transfer - amount with decimal values', function() {

            transfer.set('payee', Ember.Object.create({
                getTransferVO: function() {
                    return {
                        payeeId: '2'
                    };
                }
            }));
            spyOn(transfer, 'isIBFTTransfer').andReturn(true);
            spyOn(transfer, 'isVMTTransfer').andReturn(false);
            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('100.01');
            } catch(e) {
            }
            expect(BreezeException.create).toHaveBeenCalledWith({errorMessage: App.i18n.getTranslations().get('error.decimalAmountTransferError')});
        });
        it('VMT transfer - amount with decimal values', function() {

            transfer.set('payee', Ember.Object.create({
                getTransferVO: function() {
                    return {
                        payeeId: '4'
                    };
                }
            }));
            spyOn(transfer, 'isIBFTTransfer').andReturn(false);
            spyOn(transfer, 'isVMTTransfer').andReturn(true);
            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('100.01');
            } catch(e) {
            }
            expect(BreezeException.create).toHaveBeenCalledWith({errorMessage: App.i18n.getTranslations().get('error.decimalAmountTransferError')});
        });
    });
});

describe('App.CreditCardPayment', function() {
    var transfer;
    beforeEach(function(){
        transfer = App.CreditCardPayment.create({
        });
    });

    describe('validation', function() {
        it('amount less than .01', function() {
            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('0.0');
            } catch(e) {
            }
            expect(BreezeException.create).toHaveBeenCalledWith({errorMessage: App.i18n.getTranslations().get('error.minimumAmountOwnAccountError')});
        });

        it('valid amount', function() {
            spyOn(BreezeException, 'create');
            try {
                transfer.validateAmount('100.0');
            } catch(e) {
            }
            expect(BreezeException.create).not.toHaveBeenCalled();
        });
    });
});

describe('App.ViewAndPayBillPayment', function() {
    var transfer;
    beforeEach(function(){
        transfer = App.ViewAndPayBillPayment.create({
            "channel": "IBKBMW",
            "billerTransactionType" : 'VPB',
            "currencyCode": "INR"
        });

        var viewbillPayee = App.ViewAndPayBillPayee.create({
            "payee": {
            "configList": [
                {
                    "id": 205,
                    "merchantId": "000000000528",
                    "fieldName": "Circle Code",
                    "fieldLength": 4,
                    "fieldRequired": false,
                    "orderSequence": 3,
                    "lang": "en",
                    "fieldGroup": 2
                }
            ],
                "merchantLocation": "ALL INDIA",
                "payeeShortNameWeb": "SCB biller",
                "payByCard": true,
                "drAccount": "1231234",
                "drAccountCCY": "   ",
                "customField1": "58642456789",
                "customField2": "9137114129",
                "payeeId": 3228,
                "payeeType": "0",
                "payeeName": "VODAFONE MOBILE",
                "payeeStatus": "A",
                "payeeShortName": "SCB biller",
                "merchantId": "000000000528",
                "merchantCategory": ""
        },
            "consumerNumber": "000000000528",
            "regdBillerStatus": "UP",
            "billerCode": "000000000528",
            "billerName": "AIRTEL MOBILE",
            "location": "ALL INDIA",
            "billerAccntNumber": "42791238136",
            "billerAccountPin": 0,
            "billerAccntCurrencyType": "INR",
            "billerType": "Telecom",
            "seqNo": 0,
            "customerEbid": "9171981351",
            "billerTypeCode": "4812",
            "billerId": 3228,
            "billAmount": 129,
            "dueDate": "2012-06-21T00:00:00.000+0530"
        });

        transfer.set('payee', viewbillPayee);
        transfer.set('fromAccount', App.HaveAccount.create({
                "accountNumber": "22506104458",
                "currencyCode": "INR",
                "productCode": "DDA",
                "subProductCode": "159",
                "productIndex": "F-0"
            }
        ));
    });

    it('transferDataVO', function(){
        var expectedObject = {
            "payee": {
                "biller": {
                    "billerCode": "000000000528",
                    "billerType": "Telecom",
                    "billerTypeCode": "4812",
                    "billerAccntNumber": "42791238136",
                    "billerAccntCurrencyType": "INR",
                    "billerName": "AIRTEL MOBILE",
                    "consumerNumber": "000000000528"
                },
                "payeeStatus": "A",
                "payeeType": "0",
                "payeeId": 3228
            },
            "fromAccount": {
                "accountNumber": "22506104458",
                "currencyCode": "INR",
                "productCode": "DDA",
                "subProductCode": "159",
                "productIndex": "F-0"
            },
            "currencyCode": "INR",
            "amount": "129",
            "billerTransactionType": "VPB",
            "transferDate": "2012-06-01",
            "remark": null,
            "channel": "IBKBMW",
            "recurring": {
                "isRecurring": false,
                "startDate": null,
                "endDate": null,
                "frequency": ""
            }
        };

        transfer.set('amount', "129");
        transfer.set('transferDate', "2012-06-01");

        expect(JSON.stringify(transfer.transferDataVO())).toBe(JSON.stringify(expectedObject));
    });

    it('displayableObject', function(){

        var expectedObject =  [
            { "key": "To","value": "ALL INDIA, VODAFONE MOBILE"
            },
            {"key": "From","value": ", 22506104458"
            },
            {"key": "Amount",
                "value": {
                    "currencyCode": "INR",
                    "amount": "129"
                },
                "isAmount": true,
                "isNegative": false
            },
            {
                "key": "Circle Code",
                "value": "58642456789"
            },
            {
                "key": "Date",
                "value": "2012-06-01",
                "isDate": true
            }
        ];

        transfer.set('amount', "129");
        transfer.set('transferDate', "2012-06-01");
        expect(JSON.stringify(transfer.get('displayableObject'))).toBe(JSON.stringify(expectedObject));

    });
});


